package org.linlinjava.litemall.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.web.annotation.LogAnno;
import org.linlinjava.litemall.web.annotation.LoginShop;
import org.linlinjava.litemall.web.annotation.LoginUser;
import org.linlinjava.litemall.web.service.WebBalanceSrevice;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;

@Api(tags = "POS余额充值API")
@RestController
@RequestMapping("/web/balance")
@RequiredArgsConstructor
public class WebBalanceController {

    private final WebBalanceSrevice webBalanceSrevice;

    @ApiOperation(value = "POS余额充值-「查询账户｜会员码」")
    @ApiImplicitParam(name = "membershipCode",value = "会员码",required = true)
    @GetMapping(value = "/enquiryAccount")
    @LogAnno
    public ResponseUtil.Response enquiryAccount(@RequestParam("membershipCode")String membershipCode){
        return webBalanceSrevice.enquiryAccount(membershipCode);
    }

    @ApiOperation(value = "POS余额充值-「账户充值｜现金」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "amount",value = "金额",required = true),
            @ApiImplicitParam(name = "membershipCode",value = "会员码",required = true),
            @ApiImplicitParam(name = "receiveAmount",value = "收取金额"),
            @ApiImplicitParam(name = "deviceNo",value = "设备编号")
    })
    @PutMapping(value = "rechargeByCash")
    @LogAnno
    public ResponseUtil.Response rechargeByCash(
            @RequestParam("amount") @NotBlank BigDecimal amount,
            @RequestParam("membershipCode") @NotBlank String membershipCode,
            @ApiIgnore  @LoginShop Integer shopId,@ApiIgnore  @LoginUser Integer userId,
            @RequestParam("receiveAmount")BigDecimal receiveAmount,
            @RequestParam("deviceNo")String deviceNo){
        return webBalanceSrevice.rechargeByCash(amount,membershipCode,shopId,userId,receiveAmount,deviceNo);
    }

    @ApiOperation(value = "POS余额充值-「账户充值｜Clover保存交易记录」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "externalId",value = "externalId"),
            @ApiImplicitParam(name = "paymentId",value = "paymentId"),
            @ApiImplicitParam(name = "orderId",value = "clover支付ID"),
            @ApiImplicitParam(name = "amount",value = "充值金额"),
            @ApiImplicitParam(name = "cardNo",value = "信用卡卡号"),
            @ApiImplicitParam(name = "cardType",value = "信用卡类型"),
            @ApiImplicitParam(name = "membershipCode",value = "会员码"),
    })
    @PutMapping("rechargeSaveByClover")
    @LogAnno
    public ResponseUtil.Response rechargeSaveByClover(@RequestParam String externalId,
                                                      @RequestParam String paymentId,
                                                      @RequestParam String orderId,
                                                      @RequestParam("amount")@NotBlank BigDecimal amount,
                                                      String cardNo, String cardType,
                                                      @RequestParam String membershipCode,
                                                      @ApiIgnore  @LoginUser Integer userId,
                                                      @ApiIgnore @LoginShop Integer shopId){
        return webBalanceSrevice.rechargeSaveByClover(externalId,paymentId,orderId,amount,cardNo,cardType,membershipCode,userId,shopId);
    }

    @ApiOperation(value = "POS余额充值-「账户充值｜礼物卡」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardNo",value = "礼物卡号",required = true),
            @ApiImplicitParam(name = "amount",value = "充值金额",required = true),
            @ApiImplicitParam(name = "membershipCode",value = "用户会员号",required = true)
    })
    @PutMapping("rechargeByGiftCard")
    @LogAnno
    public ResponseUtil.Response rechargeByGiftCard(@RequestParam("cardNo")@NotBlank String cardNo,
                                                  @RequestParam("amount")@NotBlank BigDecimal amount,
                                                  @RequestParam("membershipCode") String membershipCode,
                                                  @ApiIgnore  @LoginUser Integer userId,
                                                  @ApiIgnore @LoginShop Integer shopId){

        return webBalanceSrevice.rechargeByGiftCard(cardNo,amount,membershipCode,userId,shopId);
    }






}
